<template>
	<section>
		<!--工具条-->
		<el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
			<el-form :inline="true" :model="filters">

				<el-form-item>
					<el-button type="primary" v-on:click="findCommission">查询</el-button>
				</el-form-item>

				<el-form-item>
					<el-button type="primary" v-on:click="getCommission">提取佣金</el-button>
				</el-form-item>
			</el-form>
		</el-col>
		<!--列表-->
		<template>
			<el-table :data="recodes" highlight-current-row v-loading="loading" border  max-height="620" style="width: 100%;">
				<el-table-column type="index" width="80" label="编号">
				</el-table-column>
				<el-table-column prop="comMoney" label="佣金金额(单位元)" >
				</el-table-column>
			</el-table>
		</template>
		<!--新增界面-->
		<el-dialog title="提取佣金"  width="30%" v-model="addFormVisible" :close-on-click-modal="false">
			<el-form :model="addForm" label-width="80px" :rules="addFormRules" ref="addForm">
				<el-form-item label="提取佣金金额" prop="comMoney">
					<el-input v-model="addForm.comMoney" auto-complete="off"></el-input>
				</el-form-item>
				<el-form-item label="备注">
					<el-input type="textarea" v-model="addForm.remark"></el-input>
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click.native="addFormVisible = false">取消</el-button>
				<el-button type="primary" @click.native="addCommission" :loading="addLoading">提交</el-button>
			</div>
		</el-dialog>
	</section>

</template>
<script>
	import {findCommission,addCommission} from '../../api/api';
	//import NProgress from 'nprogress'
    import moment from 'moment';
	export default {
		data() {
			return {
				filters: {
                    startTime:new Date(),
                    endTime:new Date(),
				},
                isShowSupper:JSON.parse(sessionStorage.getItem("user")).usertype === 2 ? true : false,
				start:0,
				pageSize:10,
                total:0,
				loading: false,
				recodes: [],
                addFormVisible: false,//新增界面是否显示
                addLoading: false,
                addFormRules: {
                    comMoney: [
                        { required: true, message: '请输入佣金金额', trigger: 'blur' }
                    ]
                },
                //新增界面数据
                addForm: {
                    remark: '',
                    comMoney:''
                },
			}
		},
		methods: {
			//获取用户列表
            findCommission: function () {
				let para = {
				};
				this.loading = true;
                findCommission(para).then(datas => {
                    this.loading = false;
                    let { message, code, data } = datas;
                    if (code !== "0") {
                        this.$message({
                            message: message,
                            type: 'error'
                        });
                    }else{
                        var array = new Array();
                        array.push(data);
                        this.recodes = array;
					}

                }).catch(e =>{

				});
			},getCommission:function () {
                this.addFormVisible = true;
            } ,
            addCommission: function () {
                this.$refs.addForm.validate((valid) => {
                    if (valid) {
                        this.$confirm('确认提交吗？', '提示', {}).then(() => {
                            this.addLoading = true;
                            let para = Object.assign({}, this.addForm);
                            addCommission(para).then((datas) => {
                                this.addLoading = false;
                                let { message, code, data } = datas;
                                if (code !== "0") {
                                    this.$message({
                                        message: message,
                                        type: 'error'
                                    });
                                }
                                this.addFormVisible = false;
                                this.findCommission();
                            }).catch(e =>{
                                this.listLoading = false;
                            });;
                        });
                    }
                });
            }
		},

		mounted() {
			this.findCommission();
		}
	};

</script>

<style scoped>

</style>
